package com.xbao.dao;

import com.xbao.model.Subject;
import com.xbao.model.SubjectExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface SubjectMapper {
    @SelectProvider(type=SubjectSqlProvider.class, method="countByExample")
    int countByExample(SubjectExample example);

    @DeleteProvider(type=SubjectSqlProvider.class, method="deleteByExample")
    int deleteByExample(SubjectExample example);

    @Delete({
        "delete from xsubject",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into xsubject (name, orgid, ",
        "createtime, updatetime)",
        "values (#{name,jdbcType=VARCHAR}, #{orgid,jdbcType=BIGINT}, ",
        "#{createtime,jdbcType=BIGINT}, #{updatetime,jdbcType=BIGINT})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(Subject record);

    @InsertProvider(type=SubjectSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(Subject record);

    @SelectProvider(type=SubjectSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="orgid", property="orgid", jdbcType=JdbcType.BIGINT),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.BIGINT),
        @Result(column="updatetime", property="updatetime", jdbcType=JdbcType.BIGINT)
    })
    List<Subject> selectByExample(SubjectExample example);

    @Select({
        "select",
        "id, name, orgid, createtime, updatetime",
        "from xsubject",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="orgid", property="orgid", jdbcType=JdbcType.BIGINT),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.BIGINT),
        @Result(column="updatetime", property="updatetime", jdbcType=JdbcType.BIGINT)
    })
    Subject selectByPrimaryKey(Long id);

    @UpdateProvider(type=SubjectSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Subject record, @Param("example") SubjectExample example);

    @UpdateProvider(type=SubjectSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Subject record, @Param("example") SubjectExample example);

    @UpdateProvider(type=SubjectSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Subject record);

    @Update({
        "update xsubject",
        "set name = #{name,jdbcType=VARCHAR},",
          "orgid = #{orgid,jdbcType=BIGINT},",
          "createtime = #{createtime,jdbcType=BIGINT},",
          "updatetime = #{updatetime,jdbcType=BIGINT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Subject record);
}